import tornado.web


class FileHandler(tornado.web.RequestHandler):

    async def post(self):
        """文件上传"""
        file_metas = self.request.files['file']
        print(file_metas)
        for meta in file_metas:
            filename = meta['filename']
            filepath = "./" + filename
            with open(filepath, 'wb') as up:
                up.write(meta['body'])
        self.write('finished!')

    async def get(self):
        """文件下载"""
        # Content-Type这里我写的时候是固定的了，也可以根据实际情况传值进来
        self.set_header('Content-Type', 'application/octet-stream')
        # 读取的模式需要根据实际情况进行修改
        with open('./quality-check.tar', 'rb') as f:
            while True:
                data = f.read(100)
                if not data:
                    break
                self.write(data)
        # 记得要finish
        self.finish()
